/**
 * Copyright 2010 Creative Works, Inc.
 * Creative Works licenses this file to you under the Apache License, version
 * 2.0 (the "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *    http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.  See the License for the specific language governing
 * permissions and limitations under the License.
 */
package org.sendvox.freswitch.core;

import java.io.PrintStream;
import java.io.PrintWriter;

public class ConnectionException extends Exception {

	private static final long serialVersionUID = -3540251261842095801L;

	private Exception underlyingException;
	private String host;
	private String message;

	public ConnectionException(Exception underlyingException, String host) {
		super("Connection error [host: " + host, underlyingException);
		this.underlyingException = underlyingException;
		this.host = host;
	}

	public ConnectionException(Exception underlyingException, String message,
			String host) {
		this(underlyingException, host);
		this.message = message;
	}

	public Exception getUnderlyingException() {
		return underlyingException;
	}

	public void printStackTrace() {
		if (underlyingException != null) {
			underlyingException.printStackTrace();
		} else {
			super.printStackTrace();
		}
	}

	public void printStackTrace(PrintStream stream) {
		if (underlyingException != null) {
			underlyingException.printStackTrace(stream);
		} else {
			super.printStackTrace(stream);
		}
	}

	public void printStackTrace(PrintWriter writer) {
		if (underlyingException != null) {
			underlyingException.printStackTrace(writer);
		} else {
			super.printStackTrace(writer);
		}
	}

	public String getMessage() {
		return message;
	}

	/**
	 * @return the host
	 */
	public String getHost() {
		return host;
	}

}
